<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;
use OT\DataDictionary;

/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class RankingpcController extends HomeController {
    /*
     * 左上角数据
     * @ shuju 数据库名
     * @ return string list 返还数据
     * */
//    public function header(){
//            $listss = M('shuju')->find();
//                    var_dump($listss);exit;
//            $this->assign('listss',$listss['chengjiaoliang']);
//            $this->display();
//    }
    /*
     * 排行榜
     * @ params string num 页码
     * @ market_data 数据库名
     * @ return string list 返还数据
     * */
    public function ranking(){
        $num = $_POST['num'] ? $_POST['num']:'1';
        $list=M('market_data')->order("market desc")->limit(($num - 1)*10,10)->select();
        $this->assign('list',$list);
        $this->display();
    }
    /*
     * 最新公告
     * @ document 关联表
     * @ picture 公告图片表
     * @ document_article 公告详情表
     * @ category 公告目录表
     * @ return string list 返回数据
     * @ return string c_id 返回点击id
     * */
    public function annc(){
        $list = M('document')
            ->alias('d')
            ->join('lz88_picture as p ON p.id= d.cover_id')
            ->join('lz88_document_article as e ON e.id=d.id')
            ->join('lz88_category as c ON c.id=d.category_id ')
            ->where(array('d.category_id'=>$_POST['c_id']?$_POST['c_id']:'45'))
            ->field('p.path,e.id,c.title,d.update_time')
            ->select();
        //var_dump($list);exit;
        $this ->assign('list',$list);
        $this -> assign('c_id',$_POST['c_id'] );
        $this->display();
    }
    /*
     * 横幅公告
     * @ document 公告标题表
     * @ document_article 公告详情表
     * @ return array list 返还数据
     * */
    public function banner_annc(){
        $list = M('document')
            ->alias('d')
            ->join('lz88_document_article as e ON e.id=d.id')
            ->where('d.id = 17')
            ->field('d.title,e.content')
            ->find();
        $this ->assign('list',$list);
        $this->display();
    }
    /*
     * 搜索框
     * @ params varchar keyword 搜索关键字
     * @ params market_data 货币详情表
     * @ return array list 返还数据
     * */
    public function found(){
        $result = array('code'=>1,'msg'=>'货币详情查询成功','data'=>array());
        $data['hb_name']=array("like","%".$_POST['keyword']."%");
        $list = M('market_data')->where($data)->field('hb_picture,hb_name,market,price,number,volume,amount,tendency')->select();
        if($list){
            $result['data'] = $list;
            echo $result;
        }else{
            $result['msg'] = '没有查询到该货币';
            echo $result;
        }
        $this ->assign('list',$list);
        $this->display();
    }

    /*
     * 货币实时数据
     * @ params char key 搜索的关键字
     * @author 大雷
     * @time 2018/10/25
     * */
    public function real_time(){
        $key = $_POST['key'];
        switch ($key){
            case $key == "Bitcoin-比特币":
                $list = file_get_contents("http://api.feixiaohao.com/platformrank/bithumb/");
                break;
            case $key == "OKEX":
                $list = file_get_contents("http://api.feixiaohao.com/platformrank/okex/");
                break;
            case $key == "币安网-Binance":
                $list = file_get_contents("http://api.feixiaohao.com/platformrank/binance/");
                break;
            case $key == "火币全球站-Huobi":
                $list = file_get_contents("http://api.feixiaohao.com/platformrank/huobipro/");
                break;
            case $key == "Bitfinex":
                $list = file_get_contents("http://api.feixiaohao.com/platformrank/bitfinex/");
                break;
            case $key == "HitBTC":
                $list = file_get_contents("http://api.feixiaohao.com/platformrank/hitbtc/");
                break;
            case $key == "ZB网-ZB":
                $list = file_get_contents("http://api.feixiaohao.com/platformrank/zb/");
                break;
        }
        $this->assign('list',$list);
        $this->display();
    }
}